package com.maxuxu.chat.testTcp;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class ChattestClient {
    public static void main(String[] args) {
        Socket socket = null;
        OutputStream outputStream = null;
        try {
//            1. 获取服务器端的地址和端口号
            InetAddress serverIP = InetAddress.getByName("127.0.0.1");
            int port = 9999;
//            2. 创建一个socket连接
             socket = new Socket(serverIP, port);
//            3. 发送消息 io 流
             outputStream = socket.getOutputStream();
            outputStream.write("hello,welcome".getBytes());

        }
        catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (outputStream!=null){
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (socket!=null){
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        }
    }
}
